﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Resources;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace KPIS.GERP.Models.HRM
{
    [Table("hrm_mp_positions"), DataContract]
    public class Position
    {
        public Position()
        {
            RecordStatus = "U";

            LowerPositions = new HashSet<Position>();
            WorkingLowerPositions = new HashSet<Position>();
        }

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember, Display(Name = "PosId", ResourceType = typeof(Resources.PositionResource))]
        [Column("pos_seq")]
        public int PosId { get; set; }

        [DataMember, Display(Name = "PosNo", ResourceType = typeof(Resources.PositionResource))]
        [Column("pos_ref")]
        public int? PosNo { get; set; }

        [DataMember, Display(Name = "Name", ResourceType = typeof(Resources.PositionResource))]
        [Column("pos_name")]
        public string Name { get; set; }

        [ForeignKey("UpperPosition")]
        [DataMember, Display(Name = "UpperPosId", ResourceType = typeof(Resources.PositionResource))]
        [Column("upper_pos_seq")]
        public int? UpperPosId { get; set; }

        [ForeignKey("WorkingUpperPosition")]
        [DataMember, Display(Name = "WorkingUpperPosId", ResourceType = typeof(Resources.PositionResource))]
        [Column("working_upper_pos_seq")]
        public int? WorkingUpperPosId { get; set; }

        [ForeignKey("JobSite")]
        [DataMember, Display(Name = "JobSiteId", ResourceType = typeof(Resources.PositionResource))]
        [Column("job_site_seq")]
        public int? JobSiteId { get; set; }

        [ForeignKey("FieldPosition")]
        [DataMember, Display(Name = "FieldPosId", ResourceType = typeof(Resources.PositionResource))]
        [Column("field_pos_seq")]
        public int? FieldPosId { get; set; }

        [ForeignKey("ExecutivePosition")]
        [DataMember, Display(Name = "ExecPosId", ResourceType = typeof(Resources.PositionResource))]
        [Column("exec_pos_seq")]
        public int? ExecPosId { get; set; }

        [ForeignKey("MasEmployeeType")]
        [DataMember, Display(Name = "EmpTypeId", ResourceType = typeof(Resources.PositionResource))]
        [Column("emp_type_seq")]
        public int? EmpTypeId { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "DefinedDate", ResourceType = typeof(Resources.PositionResource))]
        [Column("date_defined")]
        public DateTime? DefinedDate { get; set; }

        [DisplayFormat(DataFormatString = "0:dd/MM/yyyy")]
        [DataMember, Display(Name = "MoneySupportDate", ResourceType = typeof(Resources.PositionResource))]
        [Column("date_money_support")]
        public DateTime? MoneySupportDate { get; set; }

        [DataType(DataType.Currency)]
        [DataMember, Display(Name = "SalaryQuota", ResourceType = typeof(Resources.PositionResource))]
        [Column("salary_quota")]
        public decimal? SalaryQuota { get; set; }

        [DataType(DataType.Currency)]
        [DataMember, Display(Name = "SalaryMin", ResourceType = typeof(Resources.PositionResource))]
        [Column("salary_min")]
        public decimal? SalaryMin { get; set; }

        [DisplayFormat(DataFormatString = "#,##0.00")]
        [DataMember, Display(Name = "SalaryMax", ResourceType = typeof(Resources.PositionResource))]
        [Column("salary_max")]
        public decimal? SalaryMax { get; set; }

        [DataType(DataType.Currency)]
        [DataMember, Display(Name = "PosExecSalary", ResourceType = typeof(Resources.PositionResource))]
        [Column("pos_exec_salary")]
        public decimal? PosExecSalary { get; set; }

        [DataType(DataType.MultilineText)]
        [DataMember, Display(Name = "JobDescription", ResourceType = typeof(Resources.PositionResource))]
        [Column("job_description")]
        public string JobDescription { get; set; }

        [ForeignKey("MasPositionStatus")]
        [DataMember, Display(Name = "PosStatusId", ResourceType = typeof(Resources.PositionResource))]
        [Column("pos_status")]
        public int PosStatusId { get; set; }

        [DataType(DataType.MultilineText)]
        [DataMember, Display(Name = "Remarks", ResourceType = typeof(Resources.PositionResource))]
        [Column("remarks")]
        public string Remarks { get; set; }

        [EnumDataType(typeof(SYS.RecordStatus.EnumRecordStatus))]
        [DataMember, Display(Name = "RecordStatus", ResourceType = typeof(Resources.PositionResource))]
        [Column("record_status")]
        public string RecordStatus { get; set; }

        [Column("created_by")]
        public int? CreatedBy { get; set; }
        [Column("created_when")]
        public DateTime? CreatedWhen { get; set; }
        [Column("updated_by")]
        public int? UpdatedBy { get; set; }
        [Column("updated_when")]
        public DateTime? UpdatedWhen { get; set; }

        [DataMember]
        public virtual Position UpperPosition { get; set; }

        [DataMember]
        public virtual Position WorkingUpperPosition { get; set; }

        [DataMember]
        public virtual HRM.JobSite JobSite { get; set; }

        [DataMember]
        public virtual FieldPosition FieldPosition { get; set; }

        [DataMember]
        public virtual ExecutivePosition ExecutivePosition { get; set; }

        [DataMember]
        public virtual MasEmployeeType MasEmployeeType { get; set; }

        [DataMember]
        public virtual MasPositionStatus MasPositionStatus { get; set; } 

        [DataMember]
        public virtual ICollection<Position> LowerPositions { get; set; }

        [DataMember]
        public virtual ICollection<Position> WorkingLowerPositions { get; set; }

        [NotMapped]
        public string PosText
        {
            get
            {
                return PosNo + " : " + Name;
            }
        }
    }
}
